﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


namespace BLL.LibrarySys
{

    /// <summary>
    /// T_PUB_LIBRARYOUT
    /// </summary>
    public class T_PUB_LIBRARYOUT
    {
        private readonly DALL.LibrarySys.T_PUB_LIBRARYOUT dal = new DALL.LibrarySys.T_PUB_LIBRARYOUT();
        public T_PUB_LIBRARYOUT()
        { }

        /// <summary>
        /// 智能提示
        /// </summary>
        /// <param name="branch_id"></param>
        /// <returns></returns>
        public DataSet GetApplyTitel(int branch_id)
        {
            return dal.GetApplyTitel(branch_id);
        }

        public DataSet GetApplyTitel()
        {
            return dal.GetApplyTitel();
        }

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.LibrarySys.T_PUB_LIBRARYOUT model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.LibrarySys.T_PUB_LIBRARYOUT model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdatePass(string id, string state, string notation, int approver)
        {
            return dal.UpdatePass(id, state, notation, approver);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateOut(string id, string state, DateTime outdate)
        {
            return dal.UpdateOut(id, state, outdate);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateIn(string id, string state, DateTime outdate)
        {
            return dal.UpdateIn(id, state, outdate);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            return dal.Delete(ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.LibrarySys.T_PUB_LIBRARYOUT GetModel(string ID)
        {

            return dal.GetModel(ID);
        }


        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
       
        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        //public List<Model.LibrarySys.T_PUB_LIBRARYOUT> GetModelList(string strWhere)
        //{
        //    DataSet ds = dal.GetList(strWhere);
        //    return DataTableToList(ds.Tables[0]);
        //}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetApplyList(int uid, int bid, string titel, int state , DateTime begintime, DateTime endtime)
        {
            string strWhere = "";
            if (uid != -1)
            {
                strWhere += string.Format(" and APPLICANT = {0}", uid);
            }
            if (bid != -1)
            {
                strWhere += string.Format(" and a.BRANCH_ID = {0}", bid);
            }
            if (!string.IsNullOrEmpty(titel))
            {
                strWhere += string.Format(" and TITEL like '%{0}%'", titel);
            }
            if (state != 0)
            {
                strWhere += string.Format(" and STATE='{0}'", state);
            }
            if (!string.IsNullOrEmpty(begintime.ToString()))
            {
                strWhere += string.Format(" and APPLY_TIME >= '{0}' ", begintime);
            }
            if (!string.IsNullOrEmpty(endtime.ToString()))
            {
                strWhere += string.Format(" and APPLY_TIME <= '{0}' ", endtime);
            }
            DataSet ds = dal.GetApplyList(strWhere);
            return ds;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetApplyInList(int uid, int bid, string titel, int state, DateTime begintime, DateTime endtime)
        {
            string strWhere = "";
            if (uid != -1)
            {
                strWhere += string.Format(" and APPLICANT = {0}", uid);
            }
            if (bid != -1)
            {
                strWhere += string.Format(" and a.BRANCH_ID = {0}", bid);
            }
            if (!string.IsNullOrEmpty(titel))
            {
                strWhere += string.Format(" and TITEL like '%{0}%'", titel);
            }
            if (!string.IsNullOrEmpty(state.ToString()))
            {
                strWhere += string.Format(" and MATERIAL_STATE = '{0}'", state);
            }
            if (!string.IsNullOrEmpty(begintime.ToString()))
            {
                strWhere += string.Format(" and APPLY_TIME >= '{0}' ", begintime);
            }
            if (!string.IsNullOrEmpty(endtime.ToString()))
            {
                strWhere += string.Format(" and APPLY_TIME <= '{0}' ", endtime);
            }
            DataSet ds = dal.GetApplyInList(strWhere);
            return ds;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        #endregion  Method
    }
}
